def isPrime(n):
    for i in range(2,n//2):
        if n % i == 0:
            return False
    return True
def getNextPrime(n):
    if isPrime(n):
        return n
    return getNextPrime(n+1)
def isPrime_nazad(n1):
    for i in range(2,n1//2):
        if n1 % i == 0:
            return False
    return True
def getNextPrime_nazad(n1):
    if isPrime_nazad(n1):
        return n1
    return getNextPrime_nazad(n1-1)
a1 = input()
b = a1.split(" ")
if len(b) != 3:
    print("Wrong input")
else:
    a = ""
    for i in b:
        if i == "zero":
            a+="0"
        elif i == "one":
            a+="1"
        elif i == "two":
            a+="2"
        elif i == "three":
            a+="3"
        elif i == "four":
            a+="4"
        elif i == "five":
            a+="5"
        elif i == "six":
            a+="6"
        elif i == "seven":
            a+="7"
        elif i == "eight":
            a+="8"
        else:
            a+="9"
    a = int(a)
    n=a
    n1 = a
    getNextPrime(n)
    getNextPrime_nazad(n1)
    if getNextPrime(n)-a > a-getNextPrime_nazad(n1):
        
        print(getNextPrime_nazad(n1))
    else:
        print(getNextPrime(n))


